<template>
  <div class="addform">
    <!-- 基本信息 -->
    <div class="duty">基本信息</div>
    <div class="clearfix">
      <div class="clearfix">
        <div class="FormPanelDiv">
          <FormPanel ref="FormPanel" :list="formList" labelWidth="140" :cols="3" formType="add" :isSubmitBtn="false" />
        </div>
        <!-- <div class="imgDiv">
          <img :src="imgUrl" alt />
        </div>-->
      </div>
      <!-- 技能信息 -->
      <div class="duty" v-show="this.dataType == 10461001 ? (this.afterSale == 10041001 ? true : false) : false">技能信息</div>
      <div class="FormPanelDiv clearfix">
        <FormPanel
          v-if="this.dataType == 10461001 ? (this.afterSale == 10041001 ? true : false) : false"
          ref="FormPanel1"
          :list="formList1"
          labelWidth="130"
          :cols="3"
          formType="add"
          :isSubmitBtn="false"
        />
      </div>
    </div>
    <div class="addformBtn">
      <el-button @click="closeDialog">返 回</el-button>
      <!-- // 2020-1-3 【更改】 增加Loadind -->
      <el-button @click="saveDialog" type="primary" :loading="saveLoading">保存</el-button>
    </div>

    <BaseDialog :visible.sync="isShow" title destroyOnClose width="30%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '10px' }">
      <div v-if="isSuccess">
        <h3 style="text-align: center;font-weight: 700;font-size: 18px;line-height: 50px;">创建员工账号成功</h3>
        <p style="margin-left: 40px;font-size: 15px;font-weight: 700;line-height: 40px;">
          登录账号：
          <span style="color:#ccc;">{{ num }}</span>
        </p>
        <p style="margin-left: 40px;font-size: 15px;font-weight: 700;line-height: 40px;">
          登录密码：
          <span style="color:#ccc;">{{ password }}</span>
        </p>
        <div style="text-align: center;margin-top: 30px;">
          <el-button @click="closeDialog">返回列表</el-button>
          <el-button @click="deploy" type="primary">立即配置权限</el-button>
        </div>
      </div>
      <div v-else>
        <h3 style="text-align: center;font-weight: 700;font-size: 18px;line-height: 50px;">创建员工账号失败，请重试~</h3>
      </div>
    </BaseDialog>
    <!--isShowIDCade  -->
    <BaseDialog :visible.sync="isShowIDCade" title destroyOnClose width="80%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '10px' }">
      <div style="line-height:40px;">
        身份证号当前已绑定员工编号：
        <span style="color:#ccc;">{{ this.userNum }}</span>
      </div>
      <p style="line-height:40px;">当前账号绑定信息：</p>
      <FormPanel ref="FormPanel2" :list="formList2" labelWidth="130" :cols="3" formType="show" :isSubmitBtn="false" />
      <div style="text-align: center;margin-top: 30px;">
        <el-button style="width: 9vw;" @click="closeDialog2">取&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;消</el-button>
        <el-button style="width: 9vw;" @click="exportUserinfo" type="primary">导入原账号信息</el-button>
      </div>
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getJsonTree } from '@/utils/index';
import { getUserInfoList } from '@/api/common/auth/userInfo/index.js';
import { getComOrgTreeList, checkCertificateId, postEmployee, getPresetRole, getComOrgTreeListDistinct } from '@/api/common/org/employeeInfo';
import { saveEmployee } from '@/api/common/auth/employeeAuth';
import { IDNumber, phone, numberCheck, email } from '@/utils/validate';
export default {
  name: 'addform',
  mixins: [dictionary],
  props: ['workGroupsData', 'maintainWorkData', 'afterSale', 'dataType'],
  data() {
    return {
      formList: this.createFormList(),
      formList1: this.createFormList1(),
      formList2: this.createFormList2(),
      imgUrl: '123',
      isShow: false,
      duplicateDocuments: false,
      titlt: '',
      isSuccess: true,
      num: '',
      password: '',
      roleNo: '',
      employeeName: '',
      userNum: '123456',
      isShowIDCade: false,
      newUserInfo: '',
      userId: '',
      type: '',
      empId: '',
      saveLoading: false
    };
  },
  created() {
    this.inputTree();
    this.init();
  },
  methods: {
    //身份证号获取出生年月日 于2019-12-17修改出生年月根据身份证号自动生成（勿删）-START
    getBirthdayFromIdCard(idCard) {
      var birthday = '';
      if (idCard != null && idCard != '') {
        if (idCard.length == 15) {
          birthday = '19' + idCard.substr(6, 6);
        } else if (idCard.length == 18) {
          birthday = idCard.substr(6, 8);
        }

        birthday = birthday.replace(/(.{4})(.{2})/, '$1-$2-');
      }

      return birthday;
    },
    //身份证号获取出生年月日 于2019-12-17修改出生年月根据身份证号自动生成（勿删）-END
    createFormList() {
      return [
        {
          type: 'DATE',
          label: '入职日期',
          fieldName: 'entryTime',
          placeholder: '',
          initialValue: '',
          //于2019-12-17修改日期去掉时分秒（勿删）-START
          // dateType: 'date',
          // format: 'yyyy-MM-dd',
          valueFormat: 'yyyy-MM-dd',
          //于2019-12-17修改日期去掉时分秒（勿删）-END
          rules: [{ required: true, message: '请选择日期', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '员工编号',
          fieldName: 'employeeNo',
          placeholder: '',
          initialValue: '.',
          disabled: true
          // rules: [{ required: true, message: '请输入员工编号', trigger: 'blur' }]
        },
        //CMS-更改-{1871【渠道管理→员工管理】新建的时候，账号允许为汉字，应该进行限制}-START
        {
          type: 'INPUT',
          label: '登录账号',
          fieldName: 'userCode',
          placeholder: '',
          initialValue: '',
          maxlength: 30,
          // rules: [{ required: true, message: '请输入登录账号', trigger: 'blur' }, { pattern: /^[a-zA-Z][A-Za-z0-9]+$/, message: '只能为字母和数字，且以字母开头', trigger: 'blur' }]
          rules: [
            { required: true, message: '请输入登录账号', trigger: 'blur' },
            { pattern: /^[a-z][a-z0-9]+$/, message: '只能为小写字母和数字，且以字母开头', trigger: 'blur' }
          ]
        },
        //CMS-更改-{1871【渠道管理→员工管理】新建的时候，账号允许为汉字，应该进行限制}-END
        {
          type: 'INPUT_TREE',
          label: '所属部门',
          fieldName: 'orgId',
          placeholder: '所属部门',
          initialValue: '',
          itemList: [],
          rules: [{ required: true, message: '请选择所属部门', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '在职状态',
          fieldName: 'employeeStatus',
          placeholder: '',
          initialValue: 10081001,
          itemList: this.createDictList('1008'),
          rules: [{ required: true, message: '请选择在职状态', trigger: 'blur' }]
        },
        {
          type: 'DATE',
          label: '离职日期',
          fieldName: 'dimissionDate',
          placeholder: '',
          initialValue: '',
          disabled: true,
          //于2019-12-17修改日期去掉时分秒（勿删）-START
          dateType: 'date',
          format: 'yyyy-MM-dd'
          //于2019-12-17修改日期去掉时分秒（勿删）-END
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '培训第一岗位',
          fieldName: 'firstPost',
          placeholder: '',
          initialValue: '',
          //长春CMS
          rules: [],
          //长春CMS
          itemList: this.createDictList('2588'),
          hidden: false
          // rules: [{ required: true, message: '请选择在职状态', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '培训第二岗位',
          fieldName: 'secondPost',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('2588'),
          hidden: false
          // rules: [{ required: true, message: '请选择在职状态', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '培训第三岗位',
          fieldName: 'thirdPost',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('2588'),
          hidden: false
          // rules: [{ required: true, message: '请选择在职状态', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '员工姓名',
          fieldName: 'employeeName',
          placeholder: '',
          initialValue: '',
          //长春CMS
          //maxlength: 30,
          //长春CMS
          rules: [
            { required: true, message: '请输入员工姓名', trigger: 'blur' },
            { min: 0, max: 30, message: '长度在 0 到 30 个字符', trigger: 'blur' }
          ]
        },
        {
          type: 'INPUT',
          label: '手机号码',
          fieldName: 'mobilePhone',
          placeholder: '',
          initialValue: '',
          maxlength: 11,
          rules: [
            { required: true, message: '请输入手机号码', trigger: 'blur' },
            { trigger: 'blur', validator: phone }
          ]
        },
        {
          type: 'SELECT',
          label: '性别',
          fieldName: 'gender',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('1002')

          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '身份证号',
          fieldName: 'certificateId',
          placeholder: '',
          initialValue: '',
          //2020/1/2  身份证校验修改格式
          //  rules: [{ required: true, message: '请输入身份证号', trigger: 'blur', validator: IDNumber }],
          rules: [
            { required: true, message: '请输入身份证号' },
            { trigger: 'blur', validator: IDNumber }
          ],
          change: val => {
            if (val) {
              if (val.length === 18) {
                this.testIDNumber(val);
                //于2019-12-17修改出生日期默认由身份证号维护带出（勿删）-START
                let birth = this.getBirthdayFromIdCard(val);
                this.formList.find(item => item.fieldName == 'birthday').initialValue = birth;
                //于2019-12-17修改出生日期默认由身份证号维护带出（勿删）-END
              }
            }
            //于2019-12-17修改出生日期默认由身份证号维护带出（勿删）-START
            else {
              this.formList.find(item => item.fieldName == 'birthday').initialValue = '';
            }
            //于2019-12-17修改出生日期默认由身份证号维护带出（勿删）-END
          }
        },
        {
          type: 'DATE',
          label: '出生日期',
          fieldName: 'birthday',
          placeholder: '',
          initialValue: '',
          //于2019-12-17修改日期去掉时分秒（勿删）-START
          disabled: true,
          format: 'yyyy-MM-dd'
          // rules: [{ required: true, message: '请选择出生日期', trigger: 'blur' }]
          //于2019-12-17修改日期去掉时分秒（勿删）-END

          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: 'Email',
          fieldName: 'eMail',
          placeholder: '',
          initialValue: '',
          rules: [
            { required: true, message: '请输入eMail' },
            { trigger: 'blur', validator: email }
          ]
        },
        {
          type: 'INPUT',
          label: '民族',
          fieldName: 'nation',
          placeholder: '',
          initialValue: '',
          maxlength: 16
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '驾驶证级别',
          fieldName: 'drivingLevel',
          placeholder: '',
          initialValue: '',
          itemList: [
            { text: 'A', value: 'A' },
            { text: 'B', value: 'B' },
            { text: 'C', value: 'C' }
          ]
          // rules: [{ required: true, message: '请选择是否冻结', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '教育程度',
          fieldName: 'degreeEdu',
          placeholder: '',
          initialValue: '',
          rules: [{ required: true, message: '请选择教育程度', trigger: 'blur' }],
          itemList: this.createDictList('1035')
          // rules: [{ required: true, message: '请选择是否冻结', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '年龄',
          fieldName: 'age',
          placeholder: '',
          initialValue: '',
          maxlength: 3,
          rules: [{ required: false, message: '请输入3位数字', trigger: 'blur', validator: numberCheck }]
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '汽车行业时长（年）',
          fieldName: 'autoTime',
          placeholder: '',
          initialValue: '',
          maxlength: 3,
          rules: [{ required: true, message: '请输入汽车行业时长', trigger: 'blur', validator: numberCheck }]
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '是否校企合作院校毕业',
          fieldName: 'cooperationSchool',
          placeholder: '',
          initialValue: '',
          rules: [{ required: true, message: '请选择是否校企合作院校毕业', trigger: 'blur' }],
          itemList: this.createDictList('1004')
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '毕业院校',
          fieldName: 'graduateSchool',
          placeholder: '',
          initialValue: '',
          rules: [{ required: true, message: '请填写毕业院校', trigger: 'blur' }],
          maxlength: 16
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },

        {
          type: 'SELECT',
          label: '是否冻结',
          fieldName: 'lockFlag',
          placeholder: '',
          initialValue: 10041002,
          itemList: this.createDictList('1004'),
          change: val => {
            console.log(val);
            if (val == 10041001) {
              this.formList.find(item => item.fieldName == 'lockCause').disabled = false;
            } else {
              this.formList.find(item => item.fieldName == 'lockCause').disabled = true;
              this.formList.find(item => item.fieldName == 'lockCause').initialValue = '';
            }
          },
          rules: [{ required: true, message: '请选择是否冻结', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '冻结原因',
          fieldName: 'lockCause',
          placeholder: '',
          initialValue: '',
          disabled: true,
          // itemList: this.createDictList('1004'),
          maxlength: 32
          // rules: [{ required: true, message: '请选择是否冻结', trigger: 'blur' }]
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          placeholder: '',
          initialValue: '',
          selfCols: 3,
          maxlength: 32
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        }
      ];
    },
    createFormList1() {
      return [
        {
          type: 'SELECT',
          label: '班组',
          fieldName: 'workgroupId',
          placeholder: '',
          initialValue: '',
          style: { width: '13.6vw' },
          itemList: this.createDictList('1004')
          //rules: [{ required: true, message: '请选择班组', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '工种',
          fieldName: 'workerTypeId',
          placeholder: '',
          initialValue: '',
          style: { width: '13.6vw' },
          itemList: this.createDictList('8041')
          //rules: [{ required: true, message: '请选择工种', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '技师等级',
          fieldName: 'technicianGrade',
          placeholder: '',
          initialValue: '',
          style: { width: '13.6vw' },
          itemList: this.createDictList('8054')
          //rules: [{ required: true, message: '请选择技师等级', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '主工位',
          fieldName: 'maintainStationId',
          placeholder: '',
          initialValue: '',
          style: { width: '13.6vw' },
          itemList: this.createDictList('1004')
          //rules: [{ required: true, message: '请选择主工位', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '副工位',
          fieldName: 'deputyStationId',
          placeholder: '',
          initialValue: '',
          style: { width: '13.6vw' },
          itemList: this.createDictList('1004')
          //rules: [{ required: true, message: '请选择副工位', trigger: 'blur' }]
        }
      ];
    },

    createFormList2() {
      return [
        {
          type: 'INPUT',
          label: '登录账号',
          fieldName: 'userCode',
          placeholder: '',
          initialValue: ''
          // rules: [{ required: true, message: '请输入登录账号', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '员工姓名',
          fieldName: 'employeeName',
          placeholder: '',
          initialValue: '',
          maxlength: 6
          // rules: [{ required: true, message: '请输入员工姓名', trigger: 'blur' },{ min: 0, max: 6, message: '长度在 0 到 6 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '手机号码',
          fieldName: 'mobilePhone',
          placeholder: '',
          initialValue: '',
          maxlength: 11
        },
        {
          type: 'SELECT',
          label: '性别',
          fieldName: 'gender',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('1002')

          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '身份证号',
          fieldName: 'certificateId',
          placeholder: '',
          initialValue: '',
          maxlength: 18
        },
        {
          type: 'DATE',
          label: '出生日期',
          fieldName: 'birthday',
          placeholder: '',
          initialValue: ''

          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: 'Email',
          fieldName: 'eMail',
          placeholder: '',
          initialValue: '',
          rules: [{ required: false, message: '请输入eMail', trigger: 'blur', validator: email }]
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '民族',
          fieldName: 'nation',
          placeholder: '',
          initialValue: '',
          maxlength: 16
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '驾驶证级别',
          fieldName: 'drivingLevel',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('1004')
          // rules: [{ required: true, message: '请选择是否冻结', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '教育程度',
          fieldName: 'degreeEdu',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('4049')
          // rules: [{ required: true, message: '请选择是否冻结', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '年龄',
          fieldName: 'age',
          placeholder: '',
          initialValue: '',
          maxlength: 3,
          rules: [{ required: false, message: '请输入3位数字', trigger: 'blur', validator: numberCheck }]
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '汽车行业时长（年）',
          fieldName: 'autoTime',
          placeholder: '',
          initialValue: '',
          maxlength: 3,
          rules: [{ required: false, message: '请输入3位数字', trigger: 'blur', validator: numberCheck }]
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '是否校企合作院校毕业',
          fieldName: 'cooperationSchool',
          placeholder: '',
          initialValue: ''
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '毕业院校',
          fieldName: 'graduateSchool',
          placeholder: '',
          initialValue: '',
          maxlength: 16
          // rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }, { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }]
        }
      ];
    },
    //校验身份证是否存在
    testIDNumber(val) {
      console.log(val, 'm123');
      checkCertificateId(val).then(res => {
        console.log(res, 'res');
        if (res.resultCode == 200) {
          this.userNum = res.data.employeeNo;
          console.log();
          if (res.data.type == 2) {
            //设置证件为重复
            this.duplicateDocuments = true;
            // 原账号状态为在职
            this.open();
          }
          //长春CMS
          else if (res.data == null) {
            //设置证件为重复
            this.duplicateDocuments = true;
            this.open();
          }
          //长春CMS
          else if (res.data.type == 3) {
            // 原账号状态为离职
            this.newUserInfo = res.data;
            this.formList2.forEach(x => {
              x.initialValue = res.data[x.fieldName];
            });
            this.isShowIDCade = true;
          } else {
            this.duplicateDocuments = false;
          }
        }
      });
    },
    //导入原账号信息
    exportUserinfo() {
      // let FormPanel2Data = this.$refs['FormPanel2'].SUBMIT_FORM()
      console.log(this.newUserInfo, 'this.newUserInfo');
      this.formList.forEach(x => {
        x.initialValue = this.newUserInfo[x.fieldName];
      });
      this.formList1.forEach(x => {
        x.initialValue = this.newUserInfo[x.fieldName];
      });
      this.userId = this.newUserInfo.userId;
      this.type = this.newUserInfo.type;
      this.empId = this.newUserInfo.empId;
      this.isShowIDCade = false;
      // postEmployee(params).then(res=>{
      //     if(res.resultCode == 200){
      //       //基础数据
      //       this.formList.forEach(x=>{
      //         x.initialValue = FormPanel2Data[x.fieldName]
      //       })
      //       // 技能
      //       this.formList1.forEach(x=>{
      //         x.initialValue = FormPanel2Data[x.fieldName]
      //       })

      //       this.closeDialog2()
      //     }
      // })
    },
    //返回
    closeDialog2() {
      this.isShowIDCade = false;
    },
    //原账号状态为在职，
    open() {
      this.$alert(`<p>身份证号当前已绑定员工编号：<i>${this.userNum}</i></p><p style="font-size: 12px;color: #ccc;">如需继续创建，请先将原账号设为离职</p>`, {
        confirmButtonText: '知道了',
        dangerouslyUseHTMLString: true,
        callback: action => {}
      });
    },
    // 创建账号
    saveDialog() {
      if (this.duplicateDocuments == true) {
        this.open();
        return;
      }

      //于2020-1-2 修改 身份证号 一直变为必填项
      //  this.formList.find(item => item.fieldName == 'certificateId').rules = [];
      let FormPanelData = this.$refs.FormPanel.SUBMIT_FORM();
      //于2019-12-17 修改 日期传入后台加上时分秒避免系统异常(勿删)-START
      FormPanelData.birthday = FormPanelData.birthday + ' 00:00:00';
      //于2019-12-17 修改 日期传入后台加上时分秒避免系统异常(勿删)-END
      console.log(FormPanelData);
      // || !this.formList[1].initialValue
      if (
        !this.formList[0].initialValue ||
        !this.formList[2].initialValue ||
        !this.formList[3].initialValue ||
        !this.formList[4].initialValue ||
        !this.formList[9].initialValue ||
        !this.formList[10].initialValue ||
        !this.formList[22].initialValue
      ) {
        this.$message({
          message: '请填写必填项',
          type: 'warning'
        });
      } else {
        let exportData = {
          type: '',
          userId: '',
          empId: ''
        };
        if (this.type == 3) {
          exportData.type = this.type;
          exportData.empId = this.empId;
          exportData.userId = this.userId;
        }
        // console.log(this.formList,this.imgUrl,"formList")
        this.params = {
          ...FormPanelData,
          workgroupId: this.formList1[0].initialValue,
          workerTypeId: this.formList1[1].initialValue,
          technicianGrade: this.formList1[2].initialValue,
          maintainStationId: this.formList1[3].initialValue,
          deputyStationId: this.formList1[4].initialValue,
          ...exportData
        };
        console.log(this.params, 'this.params');
        let isTrue = false;
        if (this.params.certificateId) {
          console.log(isTrue, 'isTrue12');
          isTrue = true;
          this.formList.find(item => item.fieldName == 'certificateId').rules = [{ required: true, trigger: 'blur', validator: IDNumber }];
        } else {
          console.log(isTrue, 'isTrue1');
          //于2020-1-2 修改 身份证号 一直变为必填项
          // this.formList.find(item => item.fieldName == 'certificateId').rules = [];

          if (!this.params.firstPost && !this.params.secondPost && !this.params.secondPost) {
            // console.log(isTrue,"isTrue1")
            isTrue = true;
          } else if (!this.params.firstPost && !this.params.secondPost) {
            // console.log(isTrue,"isTrue2")
            isTrue = true;
          } else if (!this.params.firstPost && !this.params.thirdPost) {
            // console.log(isTrue,"isTrue3")
            isTrue = true;
          } else if (!this.params.secondPost && !this.params.thirdPost) {
            // console.log(isTrue,"isTrue4")
            isTrue = true;
          } else if (this.params.firstPost == this.params.secondPost) {
            // console.log(isTrue,"isTrue5")
            isTrue = false;
            this.$message({
              message: '第一岗位、第二岗位、第三岗位所选内容不可重复',
              type: 'info'
            });
          } else if (this.params.firstPost == this.params.thirdPost) {
            // console.log(isTrue,"isTrue6")
            isTrue = false;
            this.$message({
              message: '第一岗位、第二岗位、第三岗位所选内容不可重复',
              type: 'info'
            });
          } else if (this.params.secondPost == this.params.thirdPost) {
            // console.log(isTrue,"isTrue7")
            isTrue = false;
            this.$message({
              message: '第一岗位、第二岗位、第三岗位所选内容不可重复',
              type: 'info'
            });
          } else {
            isTrue = true;
          }
        }
        console.log(isTrue, '123');
        if (isTrue) {
          this.saveLoading = true;
          this.num = this.formList[2].initialValue;
          saveEmployee(this.params).then(res => {
            console.log(res, 'res123');
            if (res.resultCode == 200) {
              // this.closeDialog('refresh')
              this.roleNo = res.data.employeeNo;
              this.employeeName = res.data.employeeName;
              // 2019-12-17 【更改】将登陆密码显示-START
              this.password = res.data.password;
              // 2019-12-17 【更改】将登陆密码显示-END
              this.isShow = true;
              this.$message({
                message: '保存成功',
                type: 'success'
              });
            }
            this.saveLoading = false;
          });
        }
      }
    },
    // saveDialog(){
    //     //全部填写后调用，暂时没有接口放到这

    //     if(this.formList[9].initialValue != '' && this.formList[9].initialValue.length != '18'){
    //         this.$message({
    //         message: '请填写正确的身份证号码',
    //         type: 'warning'
    //         });
    //     }
    //     if(this.formList[0].initialValue == '' || this.formList[1].initialValue == '' || this.formList[2].initialValue == '' ||this.formList[3].initialValue == '' ||this.formList[4].initialValue == '' ||this.formList[9].initialValue == ''||this.formList[10].initialValue == ''||this.formList[22].initialValue == ''){
    //         this.$message({
    //         message: '请填写必填项',
    //         type: 'warning'
    //         });
    //     }else{
    //         console.log(this.formList,this.imgUrl,"formList")
    //         this.num=this.formList[2].initialValue
    //         this.employeeName=this.formList[6].initialValue
    //         let params={
    //           "entryTime": this.formList[0].initialValue,
    //           "employeeNo": this.formList[1].initialValue,
    //           "userCode": this.formList[2].initialValue,
    //           "orgId": this.formList[3].initialValue,
    //           "employeeStatus": this.formList[4].initialValue,
    //           "dimissionDate": this.formList[5].initialValue,
    //           "employeeName": this.formList[6].initialValue,
    //           "mobilePhone": this.formList[7].initialValue,
    //           "gender": this.formList[8].initialValue,
    //           "certificateId": this.formList[9].initialValue,
    //           "birthday": this.formList[10].initialValue,
    //           "eMail": this.formList[11].initialValue,
    //           // "validStatus": this.formList[12].initialValue,
    //           "lockFlag": this.formList[12].initialValue,
    //           "photos": this.imgUrl,
    //           "workgroupId":this.formList[13].initialValue,
    //           "workerTypeId": this.formList[14].initialValue,
    //           "technicianGrade": this.formList[15].initialValue,
    //           "maintainStationId":this.formList[16].initialValue,
    //           "deputyStationId": this.formList[17].initialValue,
    //         }
    //         saveEmployee(params).then(res=>{
    //             if(res.resultCode == 200){
    //               this.roleNo=res.data
    //               this.isShow=true
    //             }
    //         })
    //     }
    // },
    // 立即配置权限
    deploy() {
      this.$emit('close', false, 'deploy', this.roleNo, this.employeeName);
    },
    // 返回
    closeDialog(type) {
      this.$emit('close', false, type);
    },

    // 部门树
    async inputTree() {
      const res = await getComOrgTreeListDistinct();
      var that = res.data;
      that.forEach(el => (el.text = el.text));
      that.forEach(el => (el.value = el.orgId));
      that.forEach(el => (el.parentId = el.parent));
      this.formList[3].itemList = getJsonTree(that);
      //   this.formList[3].initialValue=this.rowData.orgId
      //   this.formList[3].placeholder=this.rowData.orgName
    },
    //init
    init() {
      let time = new Date(); //根据时间戳生成的时间对象
      let year = time.getFullYear();
      let month = time.getMonth() + 1;

      if (month < 10) {
        month = '0' + month;
      }

      let date = time.getDate() > 9 ? time.getDate() : '0' + time.getDate();
      let hours = time.getHours() > 9 ? time.getHours() : '0' + time.getHours();
      let minutes = time.getMinutes() > 9 ? time.getMinutes() : '0' + time.getMinutes();
      let seconds = time.getSeconds() > 9 ? time.getSeconds() : '0' + time.getSeconds();
      let fullDate = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
      this.formList[0].initialValue = fullDate;

      //2019-12-17 【更改】车场端新建员工屏蔽培训第一、二、三岗位-START
      //如果是车场端新建员工屏蔽第一、二、三岗位
      if (this.dataType == 10461003) {
        this.formList.find(item => item.fieldName === 'firstPost').hidden = true;
        this.formList.find(item => item.fieldName === 'secondPost').hidden = true;
        this.formList.find(item => item.fieldName === 'thirdPost').hidden = true;
      }
      //2019-12-17 【更改】车场端新建员工屏蔽培训第一、二、三岗位-END
      if (this.afterSale != 10041001 || this.dataType == 10461003) {
        this.formList1.find(item => item.fieldName === 'workgroupId').hidden = true;
        this.formList1.find(item => item.fieldName === 'maintainStationId').hidden = true;
        this.formList1.find(item => item.fieldName === 'deputyStationId').hidden = true;
        this.formList1.find(item => item.fieldName === 'workerTypeId').hidden = true;
        this.formList1.find(item => item.fieldName === 'technicianGrade').hidden = true;
      }
      this.formList1.find(item => item.fieldName === 'workgroupId').itemList = this.workGroupsData;
      this.formList1.find(item => item.fieldName === 'maintainStationId').itemList = this.maintainWorkData;
      this.formList1.find(item => item.fieldName === 'deputyStationId').itemList = this.maintainWorkData;

      //第一二三岗位数据
      // this.formList.find(item => item.fieldName === 'firstPost').itemList = [];
      // this.formList.find(item => item.fieldName === 'secondPost').itemList = [];
      // this.formList.find(item => item.fieldName === 'thirdPost').itemList = [];
      // getPresetRole().then(res => {
      //   // console.log(res,"第一二三岗位数据add")
      //   res.data.map(x => {
      //     this.formList.find(item => item.fieldName === 'firstPost').itemList.push({ text: x.roleName, value: x.roleId });
      //     this.formList.find(item => item.fieldName === 'secondPost').itemList.push({ text: x.roleName, value: x.roleId });
      //     this.formList.find(item => item.fieldName === 'thirdPost').itemList.push({ text: x.roleName, value: x.roleId });
      //   });
      // });
    }
  }
};
</script>

<style lang="less" scoped>
.clearfix::after {
  content: '';
  height: 0;
  visibility: hidden;
  clear: both;
  display: block;
}
.clearfix {
  zoom: 1;
}
.addform {
  .FormPanelDiv {
    width: 99%;
    float: left;
  }
  .imgDiv {
    width: 100px;
    min-height: 150px;
    border: 1px solid #000;
    float: right;
    margin-right: 10px;
    /* position: absolute;
        right: 10%;
        top: 0; */
  }
  .addformBtn {
    text-align: center;
    // position: absolute;
    // left: 43%;
    // bottom: 10px;
  }
  .duty {
    width: 99%;
    height: 30px;
    line-height: 30px;
    margin-bottom: 5px;
    background: #eee;
    text-indent: 5px;
  }
}
</style>
